home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Revista CD Expert 8
/
Revista CD Expert nº 08 CD1.iso
/
Utilitarios
/
Programacao
/
Pacific C for DOS
/
EXAMPLES
/
SIEVE.C
< prev
next >
Wrap
C/C++ Source or Header
|
1995-03-08
|
566b
|
34 lines
#include <stdio.h>
#include <stdlib.h>
#define TRUE 1
#define FALSE 0
#define SIZE 8190
char flags[SIZE+1];
main()
{
register int k, j, i, count, prime;
printf("100 iterations of sieve\n");
for(i = 1 ; i <= 100 ; i++) {
count = 0;
for(j = 0 ; j <= SIZE ; j++)
flags[j] = TRUE;
for(j = 0 ; j <= SIZE ; j++) {
if(flags[j]) {
prime = j + j + 3;
k = j + prime;
while(k <= SIZE) {
flags[k] = FALSE;
k += prime;
}
count = count + 1;
}
}
}
printf("\n%d primes\n", count);
exit(0);
}